<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../../inc.jsp"></jsp:include>
<script type="text/javascript" charset="utf-8">
	var datagrid;//列表对象
	var shangJiBH;
	var shangJiMC;
    alert("kkkk122");
	/**
	 * 加载树
	 */
	$(function loadTree() {
	    alert("kkkk122");
		$.ajax({
			type : 'post',
			url : 'gongNengAction!tree.action?leiXing=2',
			success : function(jsonStr) {
				tree = (new Function("return " + jsonStr))();
				if (tree[0].id != 0) {
					shangJiBH = tree[0].id; //设置默认父菜单ID
					shangJiMC = tree[0].text; //设置默认父菜单名
				}
				$(function() {
					treeObj = $('#gongNengTree').tree({
						data : tree,
						lines : true,
						onClick : function(node) {
							shangJiBH = node.id; //设置默认父菜单ID
							shangJiMC = node.text; //设置默认父菜单名
							loadDatagrid(node);
						},
						onDblClick : function(node) {
							if (node.state == 'closed') {
								$(this).tree('expand', node.target);
							} else {
								$(this).tree('collapse', node.target);
							}
						}
					});
				});
			}

		});
	});

	/**
	 *加载列表
	 **/
	$(function loadDatagrid(node) {
		shangJiMC = node.text;
		shangJiBH = node.id;
		if (node.id == undefined || node.id == 0) {
			node.id = '';
		}
		
		console.info(node.id);
		
		datagrid = $('#datagrid').datagrid({
			url : 'gongNengAction!datagrid.action?shangJiBH = ' + node.id + '&leiXing=1',
			title : '',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 10,
			pageList : [ 10, 20, 30, 40 ],
			fit : true,
			fitColumns : true,
			nowrap : false,
			border : false,
			idField : 'bianHao',
			//		sortName : 'id',
			//		sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			//		frozenColumns : [ [ 
			columns : [ [ //字段定义
			{
				title : '',
				field : 'leiXing',
				sortable : true,
				checkbox : true
			}, {
				title : '功能编号',
				field : 'bianHao',
				width : 90
			}, {
				title : '功能名称',
				field : 'mingCheng',
				width : 90,
				formatter : function(value, obj, rowNum) {
					return "<a href='javascript:void(0);view(" + rowNum + ")'>" + value + "<a>";
				}
			}, {
				title : '功能链接',
				field : 'luJing',
				width : 150
			},{
				title : '排序编号',
				field : 'shunXuBH',
				width : 30
			}, {
				title : '状态',
				field : 'zhuangTaiStr',
				width : 50
			} ] ],
			toolbar : [ { //工具栏定义
				text : '<s:text name="add"></s:text>',
				iconCls : 'icon-add',
				handler : function() {
					append();
				}
			}, '-', {
				text : '<s:text name="edit"></s:text>',
				iconCls : 'icon-edit',
				handler : function() {
					edit();
				}
			}, '-', {
				text : '<s:text name="delete"></s:text>',
				iconCls : 'icon-remove',
				handler : function() {
					remove();
				}
			}, '-' ],
			onRowContextMenu : function(e, rowIndex, rowData) {//右键菜单定义
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});

	});

	/**
	 *查看
	 **/
	function view(rowNum) {
		var rows = datagrid.datagrid("getRows");
		var node = rows[rowNum];
		var p = parent.dagong.dialog({
			title : '<s:text name="view"></s:text>gongneng',
			href : 'gongNengAction!gongNengView.action',//加载页面
			width : 450,
			height : 300,
			onLoad : function() {
				var f = p.find('form');
				parent.$.messager.progress('close');
				f.form('load', node);
			}
		});
	}

	/**
	 *添加
	 **/
	function append() {
		var p = parent.dagong.dialog({
			title : '<s:text name="add"></s:text>gongneng',
			href : 'gongNengAction!gongNengAdd.action',
			width : 450,
			height : 300,
			buttons : [ {
				text : '<s:text name="add"></s:text>',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : 'gongNengAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.dagong.messagerShow({
								msg : json.msg,
								title : '<s:text name="prompt"></s:text>'
							});
						}
					});
				}
			} ]
		});
	}

	/**
	 *修改
	 **/
	function edit() {
		var rows = datagrid.datagrid('getChecked');//获取选中行
		if (rows.length == 1) {//选中一行
			var node = rows[0];
			var p = parent.dagong.dialog({
				title : '<s:text name="edit"></s:text>gongneng',
				href : 'gongNengAction!gongNengEdit.action',//加载edit页面
				width : 450,
				height : 300,
				buttons : [ {
					text : '<s:text name="edit"></s:text>',
					handler : function() {
						var f = p.find('form');
						f.form('submit', {
							url : 'gongNengAction!edit.action',
							success : function(d) {
								var json = $.parseJSON(d);
								if (json.success) {
									datagrid.datagrid('reload');
									p.dialog('close');
								}
								parent.dagong.messagerShow({
									msg : json.msg,
									title : '<s:text name="prompt"></s:text>'
								});
							}
						});
					}
				} ],
				onLoad : function() {
					var f = p.find('form');
					parent.$.messager.progress('close');
					f.form('load', node);
				}
			});
		} else if (rows.length > 1) {
			parent.dagong.messagerAlert('<s:text name="prompt"></s:text>', '<s:text name="PleaseSelectARecord"></s:text>', 'error');
		} else {
			parent.dagong.messagerAlert('<s:text name="prompt"></s:text>', '<s:text name="PleaseTickToEditRecords"></s:text>', 'error');
		}
	}

	/**
	 *删除
	 **/
	function remove() {
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.dagong.messagerConfirm('<s:text name="pleaseConfirm"></s:text>', '<s:text name="DoYouWantToDeleteTheSelectedItem"></s:text>', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].bianHao);
					}
					$.ajax({
						url : 'gongNengAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							parent.dagong.messagerShow({
								title : '<s:text name="prompt"></s:text>',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.dagong.messagerAlert('<s:text name="prompt"></s:text>', '<s:text name="PleaseTickToDeleteRecords"></s:text>', 'error');
		}
	}

	/**
	 * 提交查询
	 **/
	function _search() {
	    alert("searchbun");
		datagrid.datagrid('load', dagong.serializeObject($('#searchForm')));
	}

	/**
	 * 清空查询条件
	 **/
	function cleanSearch() {
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
	}
</script>
</head>
<body>
	<div class="easyui-panel" title="&nbsp;" style="width:500px;height:200px;padding:0px;background-color: white;" data-options="fit:true,border:false">
		<div class="easyui-layout" data-options="fit:true,border:false">
			<div data-options="region:'west',split:true,border:false" style="width:260px;padding: 5px;">
				<ul id="gongNengTree"></ul>
			</div>

			<div data-options="region:'center',border:false">
				<div class="easyui-layout" data-options="fit:true,border:false">
					<div data-options="region:'north',border:false" style="height:70px;overflow:hidden;">
						<form id="searchForm">
							<div style="padding:20px; margin: 0px;height: 24px;">
								<span class="title">功能名称</span> <input type="text" name="mingCheng" class="t_d" /> <span class="title blankSpace"><s:text name="functionLinkUrl"></s:text>
								</span> <input type="text" name="luJing" class="t_d" /> <a id="" class="easyui-linkbutton blankSpace" href="javascript:void(0)" onclick="_search();">查询</a>&nbsp;&nbsp; <a id="" class="easyui-linkbutton" href="javascript:void(0)" onclick="cleanSearch();">重置</a>
							</div>
						</form>
					</div>
					<div data-options="region:'center',border:false">
						<table id="datagrid"></table>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 右键菜单 -->
	<div id="menu" class="easyui-menu" style="width:120px;display: none;">
		<div onclick="append();" data-options="iconCls:'icon-add'">
			<s:text name="add"></s:text>
		</div>
		<div onclick="edit();" data-options="iconCls:'icon-edit'">
			<s:text name="edit"></s:text>
		</div>
		<div onclick="remove();" data-options="iconCls:'icon-remove'">
			<s:text name="delete"></s:text>
		</div>
	</div>
	<!-- 右键菜单 end-->
</body>
</html>